﻿using UnityEditor;
using UnityEngine;

namespace EditorExtension
{
    public class GUILayoutAPI
    {
        #region Basic
        
        private string mTextFieldValue = "TextField: Hello IMGUI";
        private string mTextAreaValue = "TextArea:\n Hello IMGUI";
        private string mPasswordFieldValue = "PasswordField: Hello IMGUI";
        private Vector2 mScrollPosition = Vector2.zero;
        private float mSliderValue = 0.5f;
        private int mToolbarIndex = 0;
        private bool mToggleValue = false;
        private int mSelectedGridIndex = 0;
        
        public void Draw()
        {
            GUILayout.Label("Label: Hello IMGUI"); // 文本标签
            
            mTextFieldValue = GUILayout.TextField(mTextFieldValue); // 文本输入框

            mTextAreaValue = GUILayout.TextArea(mTextAreaValue); // 文本输入区域

            mPasswordFieldValue = GUILayout.PasswordField(mPasswordFieldValue, '*'); // 密码输入框
            
            // 按钮 -- 抬起时触发
            if (GUILayout.Button("Button"))
            {
                Debug.Log("Button Clicked");
            }
            
            // 重复按钮 -- 按下、抬起时触发
            if (GUILayout.RepeatButton("RepeatButton"))
            {
                Debug.Log("RepeatButton Clicked");
            }
            
            // 滚动条
            mScrollPosition = GUILayout.BeginScrollView(mScrollPosition);
            {
                // 横向布局
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label("Horizontal");
                    GUILayout.Label("Horizontal");
                    
                    // 最大化空白
                    GUILayout.FlexibleSpace();
                    
                    GUILayout.Label("Horizontal");
                }
                GUILayout.EndHorizontal();
            
                // 自动布局
                GUILayout.Box("Box");
            
                // 纵向布局
                GUILayout.BeginVertical("box");
                {
                    GUILayout.Label("Vertical");
                    GUILayout.Label("Vertical");
                    GUILayout.Label("Vertical");
                }
                GUILayout.EndVertical();
                
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label("HorizontalSlider");
                    // 水平滑动条
                    mSliderValue = GUILayout.HorizontalSlider(mSliderValue, 0f, 1f);
                }
                GUILayout.EndHorizontal();
                
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label("VerticalSlider");
                    // 竖直滑动条
                    mSliderValue = GUILayout.VerticalSlider(mSliderValue, 0f, 1f);
                }
                GUILayout.EndHorizontal();
                
                // 开辟GUI区域
                GUILayout.BeginArea(new Rect(0, 0, 100, 100));
                {
                    // GUI -- 自己定义位置
                    // GUILayout -- 自动进行位置布局
                    GUI.Label(new Rect(0, 0, 10, 10), "1");;
                }
                GUILayout.EndArea();
                
                // 窗口
                GUILayout.Window(1, new Rect(0, 0, 100, 100), (id) => { }, "Window");
                
                // 工具栏
                mToolbarIndex = GUILayout.Toolbar(mToolbarIndex, new[] {"Toolbar1", "Toolbar2", "Toolbar3"});
                
                // 空白
                GUILayout.Space(10);
                
                // 开关
                mToggleValue = GUILayout.Toggle(mToggleValue, "Toggle");
                
                // 控制宽高
                GUILayout.RepeatButton("RepeatButton", GUILayout.Width(100), GUILayout.Height(100));
                
                // 最小、最大宽高
                GUILayout.RepeatButton("RepeatButton",GUILayout.MinWidth(100), GUILayout.MaxWidth(200), GUILayout.MinHeight(100), GUILayout.MaxHeight(200));
                
                // 网格选择
                mSelectedGridIndex = GUILayout.SelectionGrid(mSelectedGridIndex, new[]
                {
                    "Toolbar1", "Toolbar2", "Toolbar3",
                    "Toolbar1", "Toolbar2", "Toolbar3",
                    "Toolbar1", "Toolbar2", "Toolbar3",
                    "Toolbar1", "Toolbar2", "Toolbar3",
                }, 3);

            }
            GUILayout.EndScrollView();
        }
        #endregion
    }
}